package com.example.x6.configurationmaintenance.Activity;

import android.app.Activity;
import android.app.Application;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Process;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;

public class PermissionActivity extends Activity {
    public static int PERMISSION_REQ = 1193046;
    private String[] mPermission = {"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.RECEIVE_BOOT_COMPLETED", "android.permission.INTERNET", "android.permission.WAKE_LOCK"};
    private List<String> mRequestPermission = new ArrayList();

    /* access modifiers changed from: protected */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= 23) {
            String[] strArr = this.mPermission;
            for (String one : strArr) {
                if (checkPermission(one, Process.myPid(), Process.myUid()) != 0) {
                    this.mRequestPermission.add(one);
                }
            }
            if (!this.mRequestPermission.isEmpty()) {
                requestPermissions((String[]) this.mRequestPermission.toArray(new String[this.mRequestPermission.size()]), PERMISSION_REQ);
                return;
            }
        }
        startActiviy();
    }

    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (Build.VERSION.SDK_INT >= 23 && requestCode == PERMISSION_REQ) {
            for (int i = 0; i < grantResults.length; i++) {
                String[] strArr = this.mPermission;
                for (String one : strArr) {
                    if (permissions[i].equals(one) && grantResults[i] == 0) {
                        this.mRequestPermission.remove(one);
                    }
                }
            }
            startActiviy();
        }
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PERMISSION_REQ && resultCode == 0) {
            finish();
        }
    }

    public void startActiviy() {
        if (this.mRequestPermission.isEmpty()) {
            final ProgressDialog mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setProgressStyle(0);
            mProgressDialog.setTitle("loading register data...");
            mProgressDialog.setCancelable(false);
            mProgressDialog.show();
            new Thread(new Runnable() {
                /* class com.example.x6.configurationmaintenance.Activity.PermissionActivity.AnonymousClass1 */

                public void run() {
                    Application application = (Application) PermissionActivity.this.getApplicationContext();
                    PermissionActivity.this.runOnUiThread(new Runnable() {
                        /* class com.example.x6.configurationmaintenance.Activity.PermissionActivity.AnonymousClass1.AnonymousClass1 */

                        public void run() {
                            mProgressDialog.cancel();
                            PermissionActivity.this.startActivityForResult(new Intent(PermissionActivity.this, MainActivity.class), PermissionActivity.PERMISSION_REQ);
                        }
                    });
                }
            }).start();
            return;
        }
        Toast.makeText(this, "PERMISSION DENIED!", 1).show();
        new Handler().postDelayed(new Runnable() {
            /* class com.example.x6.configurationmaintenance.Activity.PermissionActivity.AnonymousClass2 */

            public void run() {
                PermissionActivity.this.finish();
            }
        }, 3000);
    }
}
